package com.uenpay.im.ui.old.activity.mycollect;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.aswife.ui.MaskImageView;
import com.qyx.android.message.type.PacketType;
import com.qyx.android.weight.edittext.Emoji;
import com.uenpay.im.LinkDefs;
import com.uenpay.im.IMApplication;
import com.uenpay.im.R;
import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.utilities.QyxDateUtils;
import com.uenpay.im.view.PictureShowActivity;
import com.uenpay.util.app.base.BaseActivity;

import java.sql.Date;
import java.util.ArrayList;

public class CollectContentDetailActivity extends BaseActivity {
    private TextView middleText, from_cust_name, content, collect_time;
    private MaskImageView from_cust_avatar;
    private MaskImageView collect_image;
    private MyCollect myCollect;
    private Emoji mEmoji;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        isFullScreen = true;
        super.onCreate(savedInstanceState);
    }

    @Override
    public View bindView() {
        return null;
    }

    @Override
    public int bindLayout() {
        return R.layout.collect_content_detail;
    }

    @Override
    public void initView(View view) {
        mEmoji = new Emoji();
        initView();
        initListener();
        getData();
    }

    protected void initView() {
        myCollect = (MyCollect) getIntent().getSerializableExtra("my_collect");
        middleText = (TextView) findViewById(R.id.title_textview);
        from_cust_avatar = (MaskImageView) findViewById(R.id.from_cust_avatar);
        from_cust_name = (TextView) findViewById(R.id.from_cust_name);
        content = (TextView) findViewById(R.id.content);
        collect_image = (MaskImageView) findViewById(R.id.collect_image);
        collect_time = (TextView) findViewById(R.id.collect_time);
        middleText.setText(R.string.my_collect_detail);
    }

    protected void initListener() {

        collect_image.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                String bigpath = "";
                if (!TextUtils.isEmpty(myCollect.imgurl)) {
                    bigpath = myCollect.imgurl;
                } else {
                    return;
                }
                ArrayList<String> imgs = new ArrayList<String>();
                Intent show = new Intent(CollectContentDetailActivity.this,
                        PictureShowActivity.class);
                show.putExtra("content", bigpath);
                imgs.add(bigpath);
                show.putStringArrayListExtra("imgList", imgs);
                startActivity(show);
            }
        });

    }

    public void getData() {
        if (myCollect != null) {

            String avatar_path = APIConfiguration.getAvatarUrlNormal(
                    myCollect.fcustid, PacketType.PERSONAL);
            from_cust_avatar.SetUrl(avatar_path);
            from_cust_name.setText(myCollect.author);

            if (!TextUtils.isEmpty(myCollect.content)) {
                content.setText(mEmoji.getSpannedRate(myCollect.content, this,
                        3));
                LinkDefs.extractUrl2Link(content);
                content.setVisibility(View.VISIBLE);
            } else {
                if (!TextUtils.isEmpty(myCollect.imgurl)) {
                    collect_image.SetUrl(myCollect.imgurl);
                    collect_image.setVisibility(View.VISIBLE);
                }
            }

            try {
                collect_time.setText(getResources().getString(
                        R.string.collect_time)
                        + " "
                        + QyxDateUtils.generateDateTimeString(new Date(Long
                        .parseLong(myCollect.createtime) * 1000)));
            } catch (Exception e) {
                collect_time.setText(getResources().getString(
                        R.string.collect_time)
                        + " " + myCollect.createtime);
            }
        }

    }
}
